package com.utils.basejava.concurrent.atguigu;

import java.util.concurrent.TimeUnit;

/**
 * 线程操作资源类
 * 判断干活通知
 * 防止虚假唤醒
 * @author XR-8
 *
 */
class DeadLockData implements Runnable{
	
	private String lockA;
	private String lockB;
	
	public DeadLockData(String lockA, String lockB) {
		this.lockA = lockA;
		this.lockB = lockB;
	}

	@Override
	public void run() {
		synchronized(lockA) {
			System.out.println(Thread.currentThread().getName()+"\t"+"获得"+lockA+",并试图获得"+lockB);
//			try {
//				TimeUnit.SECONDS.sleep(2);
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
			synchronized(lockB) {
				System.out.println(Thread.currentThread().getName()+"\t"+"获得了"+lockB);
			}
			
		}
	}
	
}

public class DeadLockDemo {
	
	public static void main(String[] args) {
		String lockA = "lockA";
		String lockB = "lockB";
		new Thread(new DeadLockData(lockA,lockB),"AAA").start();
		new Thread(new DeadLockData(lockB, lockA),"BBB").start();
		
	}

}
